package cn.snowheart.comination.menu;

import java.util.ArrayList;
import java.util.List;

/**
 * 组合菜单对象
 *
 * @author liuwanxiang
 * @version 2019/07/09
 */
public class Menu extends MenuComponent {

    /**
     * 名称
     */
    private String name;

    /**
     * 描述
     */
    private String description;

    /**
     * 子菜单项的组合
     */
    private List<MenuComponent> menus = new ArrayList<>();

    public Menu(String name, String description) {
        this.name = name;
        this.description = description;
    }

    @Override
    public void add(MenuComponent menu) {
        menus.add(menu);
    }

    @Override
    public void remove(MenuComponent menu) {
        menus.remove(menu);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menus.get(index);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public void print() {
        System.out.print("\n" + getName());
        System.out.println(", " + getDescription());
        System.out.println("---------------------");

        for (MenuComponent menu : menus) {
            menu.print();
        }
    }
}
